<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>探针设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/js/xkube.js?v=1" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" lay-filter="UpdateInfo">
              <div class="layui-form-item">
                  <div class="layui-inline">
                      <div class="layui-input-inline"> 
                          <select name="containerId" id="containerId" lay-filter="containerId">
          		            </select>
                      </div>
                  </div>
              </div>
              <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>就绪探针[readiness]</legend>
              </fieldset>
             <blockquote class="layui-elem-quote">
              <div class="layui-form-item" pane="">
                  <label class="layui-form-label">检测类型</label>
                  <div class="layui-input-block">
                      <input type="radio" name="readiness_checkType" value="" lay-filter="checkType" title="无" checked="">
                      <input type="radio" name="readiness_checkType" value="HTTP" lay-filter="checkType" title="URL调用">
                      <input type="radio" name="readiness_checkType" value="TCP" lay-filter="checkType" title="端口检测">
                      <input type="radio" name="readiness_checkType" value="CMD" lay-filter="checkType" title="命令行">                                                           
                  </div>
              </div>
              <div id="urlCheckTpl">              
                  <div class="layui-form-item">
                      <label class="layui-form-label required">路径</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_path" placeholder="/" value="" class="layui-input">
                      </div>
                      <label class="layui-form-label required">端口</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_httpPort" placeholder="80" value="" class="layui-input">
                      </div>
                  </div>
              </div>
              <div id="tcpCheckTpl">              
                  <div class="layui-form-item">
                      <label class="layui-form-label required">端口</label>
                      <div class="layui-input-inline" style="width:500px">
                          <input type="text" name="readiness_tcpPort" placeholder="80" value="" class="layui-input">
                      </div>
                  </div>
              </div>
              <div id="cmdCheckTpl"> 
                  <div class="layui-form-item">
                      <label class="layui-form-label required">命令</label>
                      <div class="layui-input-inline" style="width:500px">
                          <input type="text" name="readiness_cmd" placeholder="不能为空" value="" class="layui-input">
                      </div>
                  </div>
              </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label required">延迟探测</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_initialDelaySeconds" placeholder="initialDelaySeconds,eg:20" value="" class="layui-input">
                      </div>
                      <label class="layui-form-label required">探测频率</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_periodSeconds" placeholder="periodSeconds,eg:10" value="" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label required">正常阀值</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_successThreshold" placeholder="successThreshold,eg:1" value="" class="layui-input">
                      </div>
                      <label class="layui-form-label required">异常阀值</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_failureThreshold" placeholder="failureThreshold,eg:5" value="" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label required">超时</label>
                      <div class="layui-input-inline">
                          <input type="text" name="readiness_timeoutSeconds" placeholder="timeoutSeconds,eg:5" value="" class="layui-input">
                  </div>
                </div>
              </blockquote>

              <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                <legend>存活探针[liveness]</legend>
              </fieldset>             
             <blockquote class="layui-elem-quote">
              <div class="layui-form-item" pane="">
                  <label class="layui-form-label">检测类型</label>
                  <div class="layui-input-block">
                      <input type="radio" name="liveness_checkType" value="" lay-filter="checkType2" title="无" checked=""> 
                      <input type="radio" name="liveness_checkType" value="HTTP" lay-filter="checkType2" title="URL调用">
                      <input type="radio" name="liveness_checkType" value="TCP" lay-filter="checkType2" title="端口检测">
                      <input type="radio" name="liveness_checkType" value="CMD" lay-filter="checkType2" title="命令行">                                                           
                  </div>
              </div>
              <div id="urlCheckTpl2">              
                  <div class="layui-form-item">
                      <label class="layui-form-label required">路径</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_path" placeholder="/" value="" class="layui-input">
                      </div>
                      <label class="layui-form-label required">端口</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_httpPort" placeholder="80" value="" class="layui-input">
                      </div>
                  </div>
              </div>
              <div id="tcpCheckTpl2">              
                  <div class="layui-form-item">
                      <label class="layui-form-label required">端口</label>
                      <div class="layui-input-inline" style="width:500px">
                          <input type="text" name="liveness_tcpPort" placeholder="80" value="" class="layui-input">
                      </div>
                  </div>
              </div>
              <div id="cmdCheckTpl2"> 
                  <div class="layui-form-item">
                      <label class="layui-form-label required">命令</label>
                      <div class="layui-input-inline" style="width:500px">
                          <input type="text" name="liveness_cmd" placeholder="不能为空" value="" class="layui-input">
                      </div>
                  </div>
              </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label required">延迟探测</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_initialDelaySeconds" placeholder="initialDelaySeconds,eg:20" value="" class="layui-input">
                      </div>
                      <label class="layui-form-label required">探测频率</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_periodSeconds" placeholder="periodSeconds,eg:10" value="" class="layui-input">
                      </div>

                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label required">正常阀值</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_successThreshold" placeholder="successThreshold,eg:1" value="" class="layui-input">
                      </div>
                      <label class="layui-form-label required">异常阀值</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_failureThreshold" placeholder="failureThreshold,eg:5" value="" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label required">超时</label>
                      <div class="layui-input-inline">
                          <input type="text" name="liveness_timeoutSeconds" placeholder="timeoutSeconds,eg:5" value="" class="layui-input">
                      </div>
                  </div> 
              </blockquote>                     
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    	$(document).ready(function(){
          //GetCurrClusterId();  
          GetNamespace();	
    	});		
</script>
<script>

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

      var newResp = {};
			$.ajax({
			   url: "/xkube/deploy/v1/Probe" + location.search,
			   type: "GET",
			   headers:{'X-Requested-With':'XMLHttpRequest'},
			   success: function (resp) {
					if (resp.code == 0 ) {
            newResp = resp;
        		$.each(resp.data,function(i,item){
        			if (item.containerId == 0) {
        				var html = '<option value="'+item.containerId+'" selected="">'+item.containerName+'</option>'
        			}else{
        				var html = '<option value="'+item.containerId+'">'+item.containerName+'</option>'	
        			}
        			$("#containerId").append(html);
        		});
  				  form.val('UpdateInfo', {
            	"readiness_checkType": resp.data[0].readiness_checkType
            	,"readiness_path": resp.data[0].readiness_path
            	,"readiness_httpPort": resp.data[0].readiness_httpPort
            	,"readiness_tcpPort": resp.data[0].readiness_tcpPort
      				,"readiness_cmd": resp.data[0].readiness_cmd
      				,"readiness_initialDelaySeconds": resp.data[0].readiness_initialDelaySeconds
      				,"readiness_periodSeconds": resp.data[0].readiness_periodSeconds
      				,"readiness_successThreshold": resp.data[0].readiness_successThreshold
      				,"readiness_failureThreshold": resp.data[0].readiness_failureThreshold
      				,"readiness_timeoutSeconds": resp.data[0].readiness_timeoutSeconds
      				,"liveness_checkType": resp.data[0].liveness_checkType
      				,"liveness_path": resp.data[0].liveness_path
      				,"liveness_httpPort": resp.data[0].liveness_httpPort
      				,"liveness_tcpPort": resp.data[0].liveness_tcpPort
      				,"liveness_cmd": resp.data[0].liveness_cmd
      				,"liveness_initialDelaySeconds": resp.data[0].liveness_initialDelaySeconds
      				,"liveness_periodSeconds": resp.data[0].liveness_periodSeconds
      				,"liveness_successThreshold": resp.data[0].liveness_successThreshold
      				,"liveness_failureThreshold": resp.data[0].liveness_failureThreshold
      				,"liveness_timeoutSeconds": resp.data[0].liveness_timeoutSeconds
  				  })
            if(resp.data[0].readiness_checkType == 'HTTP'){
              $("#urlCheckTpl").show();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").hide();
            }else if(resp.data[0].readiness_checkType == 'TCP') {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").show();
              $("#cmdCheckTpl").hide();     
            }else if(resp.data[0].readiness_checkType == 'CMD') {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").show();     
            }else {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").hide();     
            } 
    
            if(resp.data[0].liveness_checkType == 'HTTP'){
              $("#urlCheckTpl2").show();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").hide();
            }else if(resp.data[0].liveness_checkType == 'TCP') {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").show();
              $("#cmdCheckTpl2").hide();     
            }else if(resp.data[0].liveness_checkType == 'CMD') {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").show();     
            }else {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").hide();     
            } 
          }else{
            layer.msg(resp.msg,{icon:2});
          }
				}
		  });	

        //选择
        form.on('select(containerId)', function(data){
            //console.log(data.value); //得到被选中的值
            var id = data.value
  				  form.val('UpdateInfo', {
            	"readiness_checkType": newResp.data[id].readiness_checkType
            	,"readiness_path": newResp.data[id].readiness_path
            	,"readiness_httpPort": newResp.data[id].readiness_httpPort
            	,"readiness_tcpPort": newResp.data[id].readiness_tcpPort
      				,"readiness_cmd": newResp.data[id].readiness_cmd
      				,"readiness_initialDelaySeconds": newResp.data[id].readiness_initialDelaySeconds
      				,"readiness_periodSeconds": newResp.data[id].readiness_periodSeconds
      				,"readiness_successThreshold": newResp.data[id].readiness_successThreshold
      				,"readiness_failureThreshold": newResp.data[id].readiness_failureThreshold
      				,"readiness_timeoutSeconds": newResp.data[id].readiness_timeoutSeconds
      				,"liveness_checkType": newResp.data[id].liveness_checkType
      				,"liveness_path": newResp.data[id].liveness_path
      				,"liveness_httpPort": newResp.data[id].liveness_httpPort
      				,"liveness_tcpPort": newResp.data[id].liveness_tcpPort
      				,"liveness_cmd": newResp.data[id].liveness_cmd
      				,"liveness_initialDelaySeconds": newResp.data[id].liveness_initialDelaySeconds
      				,"liveness_periodSeconds": newResp.data[id].liveness_periodSeconds
      				,"liveness_successThreshold": newResp.data[id].liveness_successThreshold
      				,"liveness_failureThreshold": newResp.data[id].liveness_failureThreshold
      				,"liveness_timeoutSeconds": newResp.data[id].liveness_timeoutSeconds
  				  })
            if(newResp.data[id].readiness_checkType == 'HTTP'){
              $("#urlCheckTpl").show();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").hide();
            }else if(newResp.data[id].readiness_checkType == 'TCP') {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").show();
              $("#cmdCheckTpl").hide();     
            }else if(newResp.data[id].readiness_checkType == 'CMD') {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").show();     
            }else {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").hide();     
            } 
    
            if(newResp.data[id].liveness_checkType == 'HTTP'){
              $("#urlCheckTpl2").show();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").hide();
            }else if(newResp.data[id].liveness_checkType == 'TCP') {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").show();
              $("#cmdCheckTpl2").hide();     
            }else if(newResp.data[id].liveness_checkType == 'CMD') {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").show();     
            }else {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").hide();     
            }
        });

//健康检测处
//        $("#readinessCheckTpl").hide();
//        $("#livenessCheckTpl").hide();
//        $("#urlCheckTpl").hide();
//        $("#tcpCheckTpl").hide();
//        $("#cmdCheckTpl").hide();
//       $("#urlCheckTpl2").hide();
//        $("#tcpCheckTpl2").hide();
//        $("#cmdCheckTpl2").hide();

        //检测类型
        form.on('radio(checkType)', function (data) { 
            if(data.value == 'HTTP'){
              $("#urlCheckTpl").show();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").hide();
            }else if(data.value == 'TCP') {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").show();
              $("#cmdCheckTpl").hide();     
            } else if(data.value == 'CMD') {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").show();     
            }else {
              $("#urlCheckTpl").hide();
              $("#tcpCheckTpl").hide();
              $("#cmdCheckTpl").hide();     
            }    
        });
        form.on('radio(checkType2)', function (data) { 
            if(data.value == 'HTTP'){
              $("#urlCheckTpl2").show();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").hide();
            }else if(data.value == 'TCP') {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").show();
              $("#cmdCheckTpl2").hide();     
            } else if(data.value == 'CMD') {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").show();     
            } else {
              $("#urlCheckTpl2").hide();
              $("#tcpCheckTpl2").hide();
              $("#cmdCheckTpl2").hide();     
            }    
        });
        
        //监听提交
        form.on('submit(saveBtn)', function (data) {
                //data.field.appname = data.field.appname.replace(/^\s*|\s*$/g,""); //替换空格
                  console.log(data.field);
                  if (data.field.readiness_checkType == "HTTP"){
                    if (data.field.readiness_path == "" || data.field.readiness_httpPort == ""){
                        layer.msg('若勾选健康检测的就绪检查,路径和端口不能为空!', {icon: 2});
                        return false
                    }
                  }
                  if (data.field.readiness_checkType == "TCP"){
                    if (data.field.readiness_tcpPort == ""){
                        layer.msg('若勾选健康检测的tcp检测,端口不能为空!', {icon: 2});
                        return false
                    }
                  }
                  if (data.field.readiness_checkType == "CMD"){
                    if (data.field.readiness_cmd == ""){
                        layer.msg('若勾选健康检测的命令检查,命令不能为空!', {icon: 2});
                        return false
                    }
                  }

                  if (data.field.liveness_checkType == "HTTP"){
                    if (data.field.liveness_path == "" || data.field.liveness_httpPort == ""){
                        layer.msg('若勾选健康检测的就绪检查,路径和端口不能为空!', {icon: 2});
                        return false
                    }
                  }
                  if (data.field.liveness_checkType == "TCP"){
                    if (data.field.liveness_tcpPort == ""){
                        layer.msg('若勾选健康检测的tcp检测,端口不能为空!', {icon: 2});
                        return false
                    }
                  }
                  if (data.field.liveness_checkType == "command"){
                    if (data.field.liveness_cmd == ""){
                        layer.msg('若勾选健康检测的命令检查,命令不能为空!', {icon: 2});
                        return false
                    }
                  }
			          layer.confirm('确定修改?', {icon: 3, title:'提示',yes: function(index){
                     var index2 = layer.load(0, {shade: false});
                     layer.msg('稍等片刻');
                     $.ajax({
                       url: '/xkube/deploy/v1/Probe'+ location.search,
                       type: "post",
                       data: JSON.stringify(data.field),
                       dataType: "json",
                       success: function (resp) {
                                layer.close(index2);
                                 if(resp.code == 0){
                                    layer.msg('修改成功', {icon: 1});
									                  //window.location.reload();
                                 }else{
                                    layer.msg(resp.msg,{icon:2});
                                 }
                        }
                      });		  	  
                  },
                  cancel: function(index, layero){ 
                    layer.close(index);
                    layer.close(index2);
		                console.log("不操作");
                  } 
                });
              return false;
        });

    });
</script>
</html>